package thread;

/**
 * 使用匿名内部类形式来实现线程的两种创建方式
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //第一种创建方式：继承Thread类并重写run方法
        Thread t1 = new Thread(){
          public void run(){
              for (int i = 0; i < 1000; i++) {
                  System.out.println("你是谁呀？");
              }
          }
        };
        t1.start();

        //第二种创建方式：实现Running接口并重写run方法
        Runnable r2 = new Runnable() {
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("你是谁呀？");
                }
            }
        };
        Thread t2 = new Thread(r2);
        t2.start();


        Runnable r3 = ()->{

                for (int i = 0; i < 1000; i++) {
                    System.out.println("你是谁呀？");
                }
        };
        Thread t3 = new Thread(r3);
        t3.start();


        Thread t4 = new Thread(
                ()->{
                    for (int i = 0; i < 1000; i++) {
                        System.out.println("你是谁呀？");
                    }
                }
        );
        t4.start();




    }
}
